package com.woniuxy.hrp.mapper;

import com.woniuxy.hrp.entity.Mrecord;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MrecordMapper {
    @Insert("insert hrp_mrecord (pat_id,doctor_id,Medicaladvice,prescription,datetime) values(#{pat.id},#{doctor.id},#{medicaladvice},#{prescription},#{datetime})")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    public void insert(Mrecord mrecord);

    public List<Mrecord> seleByCon(Mrecord mrecord);

    /**
     * 根据患者查就诊记录
     * @param PatientId
     * @return
     */
    @Select("select * from hrp_mrecord  where pat_id=#{PatientId}")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "id",property = "doctorAndPatientAndItems",many = @Many(select = "com.woniuxy.hrp.mapper.DoctorAndPatientAndItemMapper.selectByMrecordId")),
            @Result(column = "doctor_id",property = "doctor",one = @One(select = "com.woniuxy.hrp.mapper.DoctorMapper.selectByDoctorId"))

    })
    public List<Mrecord> seleByPatientId(int  PatientId);

    @Select("select * from hrp_mrecord  where id=#{id}")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "id",property = "doctorAndPatientAndItems",many = @Many(select = "com.woniuxy.hrp.mapper.DoctorAndPatientAndItemMapper.selectByMrecordId")),
            @Result(column = "doctor_id",property = "doctor",one = @One(select = "com.woniuxy.hrp.mapper.DoctorMapper.selectByDoctorId"))
    })
    public Mrecord seleByMrecordId(int id);

    @Select("select * from hrp_mrecord  where id=#{id}")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "doctor_id",property = "doctor",one = @One(select = "com.woniuxy.hrp.mapper.DoctorMapper.selectByDoctorId"))
    })
    public Mrecord getByMrecordId(int id);
}
